import 'package:flutter/material.dart';
import 'view/login/login.dart';
import 'router/router.dart';
import 'package:go_router/go_router.dart';

//创建goRouter实例
final _router = GoRouter(
  initialLocation: '/login', //界面初始化，重定向到Login界面
  routes: $appRoutes, // 来自 routes.g.dart
  errorBuilder: (context, state) => const Login(),
);

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

void main() {
  runApp(
    MaterialApp(
      navigatorKey: navigatorKey, // ← 关键
      home: const MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
      title: 'Flutter Hooks Demo',
      theme: ThemeData(useMaterial3: true),
      // home: const Login(),
    );
  }
}
